#endcoding:utf-8
class PraisesController < ApplicationController
  def create
    if Praise.where('user_id='+uid+' AND answer_id='+params[:praise][:answer_id].to_s).any?
      render :json=>{:stat=>2}
    else
      praise = Praise.new(praise_params)
      if praise.save
        @question = Question.find(params[:praise][:question_id])
        message = "有人赞了你的回答"
        content = message_link message,question_path(@question)
        send_message(params[:praise][:other_id],content,@question.id)
        render :json=>{:stat=>1}
      else
        render :json=>{:stat=>0}
      end
    end

  end
  private
  def praise_params
    params.require(:praise).permit(:user_id,:answer_id)
  end
end
